﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SMS.Common.Silverlight;
using SMS.Controls.AdminSVC;
using SMS.Entities;

namespace SMS.Model
{
    public class AdminModel
    {
        ServiceProxy<AdminServiceClient> proxy;
        public event Action<int> ActivateDeActivateUserLoginCompleted;
        public event Action<int> ManageUserRoleSettingCompleted;
        public event Action<SMSException> OnServiceError;
        public AdminModel()
        {
            proxy = new ServiceProxy<AdminServiceClient>("Service/AdminService.svc");
            proxy.Client.ActivateDeActivateUserLoginCompleted += Client_ActivateDeActivateUserLoginCompleted;
            proxy.Client.ManageUserRoleSettingCompleted += Client_ManageUserRoleSettingCompleted;
        }

        void Client_ManageUserRoleSettingCompleted(object sender, ManageUserRoleSettingCompletedEventArgs e)
        {
            if (e.serviceError == null)
                ManageUserRoleSettingCompleted(e.Result);
            else
                OnServiceError(e.serviceError);
        }

        void Client_ActivateDeActivateUserLoginCompleted(object sender, ActivateDeActivateUserLoginCompletedEventArgs e)
        {
            if (e.serviceError== null)
                ActivateDeActivateUserLoginCompleted(e.Result);
            else
                OnServiceError(e.serviceError);
        }

        public void ActivateDeActivateUserLogin(string username, string mode)
        {
            proxy.Client.ActivateDeActivateUserLoginAsync(username, mode);
        }

        public void ManageUserRoleSetting(string username, int role)
        {
            proxy.Client.ManageUserRoleSettingAsync(username, role);
        }
    
    }
}
